<?php
/*
 * @author Jens Beyer
 * @date 04-06-2012
 */
class MyDb {
    /**
     *
     * @var DB
     */
    protected $_db;

    /**
     *
     * @var string
     */
    protected $_host;

    /**
     *
     * @var array
     */
    protected $_result;

    public function __construct($host)
    {
        $this->_host = $host;
//        echo "create DB";
    }

    public function init()
    {
        $this->_db = mysql_connect($this->_host,"root","");
        mysql_select_db("game", $this->_db);
    }

    public function close()
    {
        mysql_close($this->_db);
    }

    /**
     *
     * @param string $q
     * @return array
     */
    public function queryArray($q)
    {
        $this->init();
        $sqlQuery = mysql_query($q);
        while($dbResult = mysql_fetch_array($sqlQuery, MYSQL_ASSOC)) {
            $this->_result[] = $dbResult;
        }
        $this->close();
        return $this->_result;
    }

    /**
     *
     * @param string $q
     * @return boolean
     */
    public function execute($q)
    {
        $this->init();
        $this->_result = $sqlQuery = mysql_query($q);
        $this->close();
        return $this->_result;
    }

    public function text()
    {
//        return "hallo Db";
    }
}
